import { MusicResUrl } from "./Enum"
import MusicUtil from "./utils/MusicUtil"
import Util from "./utils/Util"

/**
 * 音频管理类。管理播放具体的音频
 */
export class MusicManager {

    private static _instance: MusicManager = null

    public static getInstance(): MusicManager {
        if (!this._instance) {
            this._instance = new MusicManager()
        }
        return this._instance
    }

    private constructor() { }

    /**
     * 播放背景音乐
     */
    public async playBGM() {
        const audio = await MusicUtil.loadMusic(MusicResUrl.BGM)
        if (!audio) { return }
        cc.audioEngine.playMusic(audio, true)
    }

    /**
     * 播放点击音效
     * @returns 
     */
    public async playClickEffect() {
        const audio = await MusicUtil.loadMusic(MusicResUrl.CLICK)
        if (!audio) { return }
        cc.audioEngine.playEffect(audio, false)
    }

    /**
     * 播放失败音效
     */
    public async playLoseEffect() {
        const audio = await MusicUtil.loadMusic(MusicResUrl.LOSE)
        if (!audio) { return }
        cc.audioEngine.playEffect(audio, false)
    }

    /**
     * 播放胜利音效
     */
    public async playWinEffect() {
        const audio = await MusicUtil.loadMusic(MusicResUrl.WIN)
        if (!audio) { return }
        cc.audioEngine.playEffect(audio, false)
    }
}